
export const get = (baseUrl, urls, token = '') => {
	
  return new Promise((resolve, reject) => {
    uni.request({
		url:baseUrl + urls,
		method: 'GET',
		header: { 
			'content-type': 'application/json',
			'Authorization': 'Bearer ' + token
		},
		success: (res) => {
			if (res.data.data.hasOwnProperty('code')) {
				setTimeout(function () {
					uni.reLaunch({
						url: '/pages/login/login'
					});
					uni.showToast({ icon:'none', title: '授权过期' })
					uni.clearStorage();
				}, 1000);
			} else {
				resolve(res.data)
			}
		},
		fail: (err) => {
			reject(err)
		}, 
		complete: () => {
			// 隐藏loadings
			setTimeout(function () {
				uni.hideLoading();
			}, 2000);
		}
    })
  })
}


export const post = (baseUrl, urls, token = '', data = {}) => {
  return new Promise((resolve, reject) => {
    uni.request({
		url:baseUrl + urls,
		data:data,
		method: 'POST',
		header: {
			'content-type': 'application/json',
			'Authorization': 'Bearer ' + token
		},
		success: (res) => {
			if (res.data.data.hasOwnProperty('code')) {
				setTimeout(function () {
					uni.reLaunch({
						url: '/pages/login/login'
					});
					uni.showToast({ icon:'none', title: '授权过期' })
					uni.clearStorage();
				}, 1000);
			} else {
				resolve(res.data)
			}
		},
		fail: (err) => {
			reject(err)
		}, 
		complete: () => {
			// 隐藏loadings
			setTimeout(function () {
				uni.hideLoading();
			}, 1000);
		}
    })
  })
}


export const put = (baseUrl, urls, token = '', data = {}) => {
  return new Promise((resolve, reject) => {
    uni.request({
		url:baseUrl + urls,
		data:data,
		method: 'PUT',
		header: {
			'content-type': 'application/json',
			'Authorization': 'Bearer ' + token
		},
		success: (res) => {
			if (res.data.data.hasOwnProperty('code')) {
				setTimeout(function () {
					uni.reLaunch({
						url: '/pages/login/login'
					});
					uni.showToast({ icon:'none', title: '授权过期' })
					uni.clearStorage();
				}, 1000);
			} else {
				resolve(res.data)
			}
		},
		fail: (err) => {
			reject(err)
		}, 
		complete: () => {
			// 隐藏loadings
			setTimeout(function () {
				uni.hideLoading();
			}, 2000);
		}
    })
  })
}